/*******************************************************************************
 * Copyright (c) 2006 CEA LIST.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA LIST - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.activitydiagram.tabbedproperties.section;

import org.eclipse.uml2.uml.BroadcastSignalAction;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.SendSignalAction;
import org.eclipse.uml2.uml.Signal;

import com.cea.papyrus.core.filters.SignalFilter;
import com.cea.papyrus.core.tabbedproperties.AbstractSelectionElementSection;

/**
 * 
 */
public class SendSignalActionSection extends AbstractSelectionElementSection{


	public SendSignalActionSection() {
		super("Sent signal", new SignalFilter());
		// TODO Auto-generated constructor stub
	}
	@Override
	public NamedElement getReferencedElementToDisplay() {
		Signal sentSignal =null;
		if( umlElement instanceof SendSignalAction){
			sentSignal=((SendSignalAction)umlElement).getSignal();}
		else{sentSignal=((BroadcastSignalAction)umlElement).getSignal();}
		return sentSignal;
	}

	@Override
	public void removeReferencedElement() {
		if( getElement() instanceof SendSignalAction){
			((SendSignalAction)getElement()).setSignal(null);}
			else{
				((BroadcastSignalAction)getElement()).setSignal(null);
			}
	}

	@Override
	public void setReferencedElement(NamedElement element) {
		if (element instanceof Signal){
			Signal signal = (Signal)element; 
			if(signal!= null){
				if(getElement() instanceof SendSignalAction){
				((SendSignalAction)getElement()).setSignal(signal);}
				else{
					((BroadcastSignalAction)getElement()).setSignal(signal);
				}
			}
		}
		
	}
}